package net.esj.basic.core.engine.template.impl;

import javax.annotation.Resource;

import net.esj.basic.core.engine.template.AbstractTemplateEngine;

import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;

import com.opensymphony.xwork2.inject.Inject;

import freemarker.template.Configuration;
import freemarker.template.Template;

public class FreemarkerTemplateEngine implements AbstractTemplateEngine<FreemarkerTemplate> {

	Configuration configuration;
	
	@Resource
	FreeMarkerConfigurer freemarkerConfig;
	
	@Override
	public FreemarkerTemplate getTemplate(String temppath) throws Exception {
		if(configuration==null){
			configuration = freemarkerConfig.getConfiguration();
		}
		Template template = configuration.getTemplate(temppath);
		return new FreemarkerTemplate(template);
	}

}
